package tomkitty.server;

import tomkitty.turdlet.*;
import tomkitty.util.*;
import java.util.*;
import java.net.*;

public class HttpRequest {

	protected String method;
	protected String version;
	protected URI uri;
	protected Hashtable<String, String[]> fields;
	protected boolean valid = true;

	public String getMethod() {
		return method;
	}

	public String getVersion() {
		return version;
	}

	public URI getUri() {
		return uri;
	}

	public Hashtable<String, String[]> getFields() {
		return fields;
	}

	public boolean isValid() {
		return valid;
	}

	public HttpRequest(String reqLine, String fieldsString) {

		HttpRequestParser p = new HttpRequestParser(reqLine, fieldsString);
		valid = true;

		if (! p.isValid()) {
			valid = false;
		} else {
			try {
				method = p.getMethod();
				version = p.getVersion();
				uri = new URI(p.getURI());
				fields = p.getFields();
			} catch (Exception e) {
				e.printStackTrace();
				valid = false;
			}
		}

	}

}


